package control;
import java.util.ArrayList;

import model.*;
import db.*;

public class LeaseCtrl
{
	DBLease dbLea = new DBLease();
	
	public LeaseCtrl()
	{
		
	}
	
	public ArrayList<Lease> getAllLeases()
	{
		ArrayList<Lease> allLea = new ArrayList<Lease>();
		allLea = dbLea.getAllLeases(false);
		return allLea;
	}
	
	public Lease getLeaseId(String id)
	{
		return dbLea.getLeaseId(id, true);
	}
	
	public Lease getLeaseCustomerId(String id)
	{
		return dbLea.getLeaseCustomerId(id, true);
	}
	
	public void insertLease(int id, String startDate, String endDate, char status, double totalPrice, int customerId) throws Exception
	{
		Lease toInsert = new Lease();
		toInsert.setId(id);
		toInsert.setStartDate(startDate);
		toInsert.setEndDate(endDate);
		toInsert.setStatus(status);
		toInsert.setTotalPrice(totalPrice);
		toInsert.setCustomerId(customerId);
		dbLea.insertLease(toInsert);
	}
	
	public int updateLease(int id, String startDate, String endDate, char status, double totalPrice, int customerId)
	{
		Lease lea = new Lease();
		lea.setId(id);
		lea.setStartDate(startDate);
		lea.setEndDate(endDate);
		lea.setStatus(status);
		lea.setTotalPrice(totalPrice);
		lea.setCustomerId(customerId);
		return dbLea.updateLease(lea);
	}
	
	public void deleteLease(String id)
	{
		dbLea.deleteLease(id);
	}
}
